package portal.beans;

import portal.common.MyStringUtils;

public class CmdBean{
	String hostName=null;
	int cpu=100;
	int memU=Integer.MAX_VALUE;
	int memT;
	int core=0;
	String status;
	public String getHostName(){
		return hostName;
	}
	public boolean setCpuAndMemU(String data){
		//System.out.println(data);
		return setCpuAndMemU(MyStringUtils.strictSpace(data).split(" "));
	}
	public boolean setCpuAndMemU(String[] data){
		if(hostName==null)
			hostName=data[0];
		if(!hostName.equals(data[0]))
			return false;
		status=data[1];
		if(status.equals("unavail"))
			return false;
		cpu=Integer.valueOf(data[5].replace("%", ""));
		if(data[12].endsWith("M"))
			memU=Integer.valueOf(data[12].replace("M", ""));
		else if(data[12].endsWith("G"))
			memU=(int) (Float.valueOf(data[12].replace("G", ""))*1024);
		return true;
	}
	public boolean setMemT(String data){
		//System.out.println(data);
		return setMemT(MyStringUtils.strictSpace(data).split(" "));
	}
	public boolean setMemT(String[] data){
		if(hostName==null)
			hostName=data[0];
		if(!hostName.equals(data[0]))
			return false;
		if(status!=null && status.equals("unavail"))
			return false;
		if(data[5].endsWith("M"))
			memT=Integer.valueOf(data[5].replace("M", ""));
		else if(data[5].endsWith("G"))
			memT=(int) (Float.valueOf(data[5].replace("G", ""))*1024);
		core = Integer.valueOf(data[9]);
		///
		return true;
	}
	public boolean isCpu(int c){
		if((100-cpu)>=c)
			return true;
		return false;
	}
	public boolean isMem(int m){
		if((memT-memU)>=m)
			return true;
		return false;
	}
	public boolean isCore(int c){
		if(core>=c)
			return true;
		return false;
	}
	public boolean isAvaliable(int core,int cpu,int mem){
//		if(false==this.isCore(core))
//			return false;
		if(false==this.isCpu(cpu))
			return false;
		if(false==this.isMem(mem))
			return false;
		return true;
	}
	public int getCpu() {
		return cpu;
	}
	public int getMemU() {
		return memU;
	}
	public int getMemT() {
		return memT;
	}
	public void setCpu(int cpu) {
		this.cpu = cpu;
	}
	public void setMemU(int memU) {
		this.memU = memU;
	}
	public void setMemT(int memT) {
		this.memT = memT;
	}
	
}
